<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>代付款页面</title>
    <link th:href="@{/showstatic/css/seat.css}" type="text/css" rel="stylesheet" />
    <link th:href="@{https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css}" rel="stylesheet" type="text/css" />
    <link th:href="@{/showstatic/css/details.css}" type="text/css" rel="stylesheet"/>
    <link th:href="@{/showstatic/js/layer-v3.0.3/layer/mobile/need/layer.css}" rel="stylesheet" type="text/css"/>
    <link th:href="@{/showstatic/layui/css/layui.css}" type="text/css" rel="stylesheet"/>
    <script type="text/javascript" th:src="@{/showstatic/js/jquery-1.7.2.min.js}"></script>
    <script type="text/javascript" th:src="@{/showstatic/js/phone.js}"></script>
    <script type="text/javascript" th:src="@{/showstatic/js/layer-v3.0.3/layer/layer.js}"></script>
    <script type="text/javascript" th:src="@{/showstatic/layui/layui.js}"></script>
</head>
<body>

<div class="whole">

    <header class="header">
        <a href="javascript:history.back(-1)" class="fa fa-angle-left"></a>
    </header>
    <!--新订单详情-->
    <div class="seat_head" style="background-color:lightgray">
        <div style="margin-left: 200px;margin-bottom: 3px">
            <h2>新订单详情：(订单总价￥:<span style="color: red;">[[${waitOrderDTO.adjustedprice}]]</span>)</h2>
        </div>
        <spam style="float: left;margin-right: 40px">
            <img th:src="${waitOrderDTO.img}" style="width: 150px;height: 200px">
        </spam>
        <h3>[[${waitOrderDTO.movename}]]</h3>
        <span style="font-size: 20px">万达影城孵化园店</span><br>
        <span style="font-size: 20px">
        	<a style="color: white">开场时间：[[${#dates.format(waitOrderDTO.begintime,"yyyy-MM-dd")}]]</a><br>
            <a style="color: white">电影时长：[[${waitOrderDTO.duration}]]&nbsp;分钟</a><br>
            <a style="color: white">[[${waitOrderDTO.hallname}]]&nbsp;&nbsp;
                <span th:each="var:${waitOrderDTO.seatList}">
                       [[${var.seatrow}]]排[[${var.seatcolumn}]]座&nbsp;&nbsp;
                </span>
            </a>
        </span>
    </div>
    <!--旧订单详情-->
    <div class="seat_head" style="height: 10px;"></div>
    <div th:if="${oldOrderDTO}!=null">
        <div class="seat_head" style="background-color:lightgray">
            <div style="margin-left: 200px;margin-bottom: 3px">
                <h2>原订单详情： (订单总价￥:<span style="color: red;">[[${oldOrderDTO.adjustedprice}]]</span>)</h2>
            </div>
            <spam style="float: left;margin-right: 40px">
                <img th:src="${oldOrderDTO.img}" style="width: 150px;height: 200px">
            </spam>
            <h4>订单号：<span id="myoldOrdernum">[[${oldOrderDTO.ordernum}]]</span></h4>
            <h3>[[${oldOrderDTO.movename}]]</h3>
            <span style="font-size: 20px">万达影城天府新区店</span><br>
            <span style="font-size: 20px">
        	<a style="color: white">开场时间：[[${#dates.format(oldOrderDTO.begintime,"yyyy-MM-dd")}]]</a><br>
           <!-- <a style="color: white">电影时长：[[${oldOrderDTO.duration}]]&nbsp;分钟</a><br>-->
            <a style="color: white">[[${oldOrderDTO.hallname}]]&nbsp;&nbsp;
                <span th:each="var:${oldOrderDTO.seatList}">
                       [[${var.seatrow}]]排[[${var.seatcolumn}]]座&nbsp;&nbsp;
                </span>
            </a>
        </span>
        </div>
    </div>
   <!-- 下方假导航-->
    <div style="margin-top: 5px;margin-left:5px;margin-right:5px;font-size: 20px">
        <span >活动与抵用券</span><span style="float: right">无可用</span><hr>
        <span >观影卡</span><span style="float: right">无可用</span><hr>
        <span >促销卡</span><span style="float: right">无可用</span><hr>
        <!--影票合计：此处需要判断是退款还是补差价：数字为正则需要补差价，数字为负则退款-->
        <span th:if="${oldOrderDTO!=null}"><!--改签状态-->
             <span >合计</span><span style="float: right;color: red">￥[[${waitOrderDTO.adjustedprice-oldOrderDTO.adjustedprice}]]</span><hr>
        </span>
        <span th:if="${oldOrderDTO==null}"><!--非改签状态-->
             <span >合计</span><span style="float: right;color: red">￥[[${waitOrderDTO.adjustedprice}]]</span><hr>
        </span>

    </div>
    <div  style="margin-top: 5px;margin-left:5px;margin-right:5px;font-size: 20px;background-color:lightblue">
        <span >手机号</span><span style="margin-left: 30px">[[${waitOrderDTO.telnumber}]]</span><i class="layui-icon layui-icon-edit" style="float: right;font-size:30px"></i>
    </div>
    <div  style="margin-top: 200px;margin-left: 300px;align-content: center">
        <span th:if="${oldOrderDTO}!=null">
             <a class="footer" href="javascript:void(0);" onclick="change()">改签</a>
        </span>
        <span th:if="${oldOrderDTO}==null">
             <a class="footer" href="javascript:void(0);" onclick="pay()">支付</a>
        </span>
    </div>
</div>

<script th:inline="javascript">
    var url = [[@{/}]];
    var newOrdernum = [[${waitOrderDTO.ordernum}]];      //新的订单号
    var payAdjustedprice =[[${waitOrderDTO.adjustedprice}]];          //订单金额
</script>

<script>

    //支付
    function pay() {
        var form = $("<form method='post'></form>");
        form.attr("action",url+"zilanxuan/pay");
        var input1 = $("<input type='hidden'>").attr("name", "tradeNo").val(newOrdernum);  //订单号
        var input2 = $("<input type='hidden'>").attr("name", "subject").val("娱乐消费");
        var input3 = $("<input type='hidden'>").attr("name", "totalAmount").val(payAdjustedprice);     //订单金额
        form.append(input1);
        form.append(input2);
        form.append(input3);
        $("body").append($(form));
        form.submit();
    }
    //改签:改签后不能再退款了，因为退了差价的订单退款时找不到支付的流水号会报错
    function change(){
        //发送请求校验是退款还是补差价还是差价为0
        $.ajax({
           url:url+"order/validChangeOrder",
           type:"post",
           data:{
             "neworderNum":newOrdernum
           },
           success:function(obj){
              //判断价钱比较结果
               if(obj.msg==1){
                  //支付补差价.重新支付
                   var difAdjustedprice = obj.result;             //改签订单差价
                   // alert("老订单号："+newOrdernum+"订单差价："+difAdjustedprice);
                   var form = $("<form method='post'></form>");
                   form.attr("action",url+"zilanxuan/pay");
                   var input1 = $("<input type='hidden'>").attr("name", "tradeNo").val(newOrdernum);   //新订单号
                   var input2 = $("<input type='hidden'>").attr("name", "subject").val("娱乐消费");
                   var input3 = $("<input type='hidden'>").attr("name", "totalAmount").val(difAdjustedprice);  //新订单补的差价
                   form.append(input1);
                   form.append(input2);
                   form.append(input3);
                   $("body").append($(form));
                   form.submit();
               }else if(obj.msg==-1){
                   //原订单退差价
                   var oldordernum = $("#myoldOrdernum").html();  //旧订单号
                   var difAdjustedprice = obj.result;             //改签订单差价
                   alert("老订单号："+oldordernum+"订单差价："+difAdjustedprice);
                   //扫码退差价。需要把新订单号传过去
                   var form = $("<form method='post'></form>");
                   form.attr("action",url+"zilanxuan/query");
                   var input1 = $("<input type='hidden'>").attr("name", "out_trade_no").val(oldordernum);     //退款订单号，老订单号
                   var input2 = $("<input type='hidden'>").attr("name", "trade_no").val("");              //退款流水号，提交请求后查询
                   var input3 = $("<input type='hidden'>").attr("name", "subject").val("娱乐消费");
                   var input4 = $("<input type='hidden'>").attr("name", "difAdjustedprice").val(difAdjustedprice);     //退款差价
                   var input5 = $("<input type='hidden'>").attr("name", "newOderNum").val(newOrdernum);         //改签新的订单号
                   form.append(input1);
                   form.append(input2);
                   form.append(input3);
                   form.append(input4);
                   form.append(input5);
                   $("body").append($(form));
                   form.submit();
               }else if(obj.msg==0){
                   //改签票价格刚好相抵，直接向controller发送请求
                   var form = $("<form method='post'></form>");
                   form.attr("action",url+"order/payOrder");
                   var input1 = $("<input type='hidden'>").attr("name", "out_trade_no").val(newOrdernum);   //新订单号
                   form.append(input1);
                   $("body").append($(form));
                   form.submit();
               }else{
                 alert("提交失败");
                 window.location.href = url+"movieshow/userorder.html";
               }
           }
       });
    }
</script>
</body>
</html>